package com.pai4j.pgc.service.community;
import com.fasterxml.jackson.core.type.TypeReference;
import com.pai4j.common.bean.PAIPageResponseBeanUtil;
import com.pai4j.common.enums.CommonStatusEnum;
import com.pai4j.common.enums.RedisKeyEnum;
import com.pai4j.common.enums.community.ResourceBehaviorTypeEnum;
import com.pai4j.common.enums.community.ResourceTypeEnum;
import com.pai4j.common.exception.StarAuthException;
import com.pai4j.common.util.JsonUtil;
import com.pai4j.common.util.ListUtil;
import com.pai4j.common.util.RedisUtil;
import com.pai4j.common.util.ThreadPoolExecutorUtil;
import com.pai4j.domain.community.vo.request.CCPathSaveRequestVO;
import com.pai4j.domain.community.vo.response.cc.CTCPathBaseVO;
import com.pai4j.domain.community.vo.response.cc.CTCPathDetailVO;
import com.pai4j.pgc.dao.community.ICCPathDAO;
import com.pai4j.pgc.entity.community.CCPathEntity;
import com.pai4j.pgc.service.behavior.AbstractResourceBehaviorService;
import com.pai4j.pgc.service.behavior.ResourceBehaviorFactory;
import com.pai4j.pgc.service.resource.ResourceService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.redis.core.DefaultTypedTuple;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.*;
import java.util.stream.Collectors;

/**
 *
 *
 * @author: CYM-pai
 * @date: 2025/10/27 14:22
 **/
@Slf4j
@Service
public class CCPathService {

    @Autowired
    private ICCPathDAO pathDAO;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private ResourceService resourceService;
    @Autowired
    private CCQuestionService questionService;
    @Autowired
    private CCExperienceService experienceService;

    public boolean isSub(String userId) {
       AbstractResourceBehaviorService attendService =
                ResourceBehaviorFactory.getBehaviorService(ResourceBehaviorTypeEnum.FOCUS.getBehavior());
       return attendService.isBehaviorFromCache(ResourceTypeEnum.CTC_PATH.getType(), 28L, userId);
    }


    /**
     * 校验栏目权限
     *
     * @param userId
     * @param pathId
     */
    public void validatePathPermission(String userId, Long pathId) {
        if (StringUtils.isBlank(userId) || pathId == null) {
            throw new StarAuthException(pathId);
        }
        AbstractResourceBehaviorService attendService =
                ResourceBehaviorFactory.getBehaviorService(ResourceBehaviorTypeEnum.FOCUS.getBehavior());
        boolean isAttend = attendService.isBehaviorFromCache(ResourceTypeEnum.CTC_PATH.getType(), 28L, userId);
        if(!isAttend) {
            throw new StarAuthException(pathId);
        }
    }


    public void sub(String userId, Long pathId) {
        CCPathEntity path = pathDAO.findById(pathId).orElse(null);
        Assert.isTrue(path != null, "星球不存在！");
        AbstractResourceBehaviorService attendService =
                ResourceBehaviorFactory.getBehaviorService(ResourceBehaviorTypeEnum.FOCUS.getBehavior());
        attendService.behavior(userId, pathId, ResourceTypeEnum.CTC_PATH.getType());
    }

    /**
     * 创建更新技术社区栏目信息
     * @param pathSaveRequest
     * @param userId
     * @return
     */
    public Long save(CCPathSaveRequestVO pathSaveRequest, String userId) {
        CCPathEntity path = this.convertEntity(pathSaveRequest, userId);
        path = save(path);
        CCPathEntity finalPath = path;
        ThreadPoolExecutorUtil.execute(() -> {
            // 刷新栏目详情缓存
            this.refreshCTCPathDetailCacheByEntity(finalPath);
            // 加入最新栏目列表缓存
            this.refreshCTCNewPathCache();
        });
        return path.getId();
    }

    /**
     * 设置栏目状态
     * @param pathId
     * @param status
     * @param userId
     */
    public void updateStatus(Long pathId, String status, String userId) {
        CCPathEntity path = pathDAO.findById(pathId).orElse(null);
        Assert.isTrue(path != null, "栏目不存在！");
        path.setStatus(status);
        path.setUpdateBy(userId);
        path.setUpdateDate(new Date());
        path = save(path);
        CCPathEntity finalPath = path;
        ThreadPoolExecutorUtil.execute(() -> {
            refreshCTCPathDetailCacheByEntity(finalPath);
            refreshCTCNewPathCache();
            refreshSubscribesPathCache();
        });
        log.info("{} 更新中文技术社区栏目 {} deleted:{}", userId, path, status);
    }

    public void updatePaidSubMoney(Long pathId, Integer money) {
        CCPathEntity path = pathDAO.findById(pathId).orElse(null);
        Assert.isTrue(path != null, "栏目不存在！");
        path.setSubMoney(money);
        path = save(path);
        CCPathEntity finalPath = path;
        ThreadPoolExecutorUtil.execute(() -> {
            refreshCTCPathDetailCacheByEntity(finalPath);
        });
    }

    public void recommend(Long pathId, String userId) {
        CCPathEntity path = pathDAO.findById(pathId).orElse(null);
        Assert.isTrue(path != null, "栏目不存在！");
        path.setRecommend(true);
        path.setUpdateBy(userId);
        path.setUpdateDate(new Date());
        path.setRecommendDate(new Date());
        path = save(path);
        log.info("{} 推荐了中文技术社区栏目 {}", userId, path);
        this.refreshRecommendPathCache();
    }

    public void cancelRecommend(Long pathId, String userId) {
        CCPathEntity path = pathDAO.findById(pathId).orElse(null);
        Assert.isTrue(path != null, "栏目不存在！");
        path.setRecommend(false);
        path.setUpdateBy(userId);
        path.setUpdateDate(new Date());
        path = save(path);
        log.info("{} 取消推荐了中文技术社区栏目 {}", userId, path);
        this.refreshRecommendPathCache();
    }

    public List<CTCPathBaseVO> getRecommendCTCPathFromCache(int size) {
        List<CTCPathBaseVO> list = getRecommendCTCPathFromCache();
        if (CollectionUtils.isEmpty(list)) {
            return list;
        }
        return list.subList(0, Math.min(size, list.size()));
    }


    public List<CTCPathDetailVO> getSubscribesPathListFromCache(String userId) {
        List<CTCPathBaseVO> list = getSubscribesPathFromCache();
        if (CollectionUtils.isEmpty(list)) {
            return new ArrayList<>();
        }
        List<CTCPathDetailVO> pathList = list.stream().map(p -> {
            return getPathBaseFromCache(p.getId());
        }).collect(Collectors.toList());
        List<Long> pathIdList = pathList.stream().map(CTCPathDetailVO::getId).collect(Collectors.toList());
        AbstractResourceBehaviorService attendService =
                ResourceBehaviorFactory.getBehaviorService(ResourceBehaviorTypeEnum.FOCUS.getBehavior());
        Map<Long, Boolean> isAttendMap = attendService.getIsBehaviorFromCache(ResourceTypeEnum.CTC_PATH.getType(), pathIdList, userId);
        for (CTCPathDetailVO p : pathList) {
            Long pathId = p.getId();
            p.setIsAttend(isAttendMap.getOrDefault(pathId, false));
        }
        return pathList;
    }

    public List<CTCPathBaseVO> getSubscribesPathFromCache() {
        String key = RedisKeyEnum.CTC_PATH_SUBSCRIBE_CACHE.getKey();
        String cache = redisUtil.get(key);
        List<CTCPathBaseVO> list;
        if (StringUtils.isNotBlank(cache)) {
            list = JsonUtil.fromJson(cache, new TypeReference<List<CTCPathBaseVO>>() {});
        } else {
            list = refreshSubscribesPathCache();
        }
        return list;
    }

    public List<CTCPathBaseVO> getRecommendCTCPathFromCache() {
        String key = RedisKeyEnum.CTC_PATH_RECOMMEND_CACHE.getKey();
        String cache = redisUtil.get(key);
        List<CTCPathBaseVO> list;
        if (StringUtils.isNotBlank(cache)) {
            list = JsonUtil.fromJson(cache, new TypeReference<List<CTCPathBaseVO>>() {});
        } else {
            list = refreshRecommendPathCache();
        }
        if (CollectionUtils.isNotEmpty(list)) {
            ListUtil.shuffle(list);
        }
        return list;
    }

    public List<CTCPathDetailVO> feed(String userId, int feedSize) {
        List<CTCPathDetailVO> feedResult = new ArrayList<>();
        if (StringUtils.isNotBlank(userId)) {
            List<CTCPathDetailVO> list = getUserAttendPathListFromCache(userId, 4);
            if (CollectionUtils.isNotEmpty(list)) {
                feedResult.addAll(list);
            }
        }
        Set<Long> pathIdSet = feedResult.stream().map(CTCPathDetailVO::getId).collect(Collectors.toSet());
        // 随机推荐
        List<CTCPathBaseVO> ctcPathBaseVOList = getRecommendCTCPathFromCache();
        for (CTCPathBaseVO ctcPathBaseVO : ctcPathBaseVOList) {
            if (feedResult.size() >= feedSize) {
                return feedResult;
            }
            if (!pathIdSet.contains(ctcPathBaseVO.getId())) {
                CTCPathDetailVO ctcPathDetail = new CTCPathDetailVO();
                ctcPathDetail.setIsAttend(false);
                ctcPathDetail.setId(ctcPathBaseVO.getId());
                ctcPathDetail.setName(ctcPathBaseVO.getName());
                ctcPathDetail.setIcon(ctcPathBaseVO.getIcon());
                ctcPathDetail.setDescription(ctcPathBaseVO.getDescription());
                feedResult.add(ctcPathDetail);
            }
        }
        return feedResult;
    }

    private List<CTCPathBaseVO> refreshRecommendPathCache() {
        String key = RedisKeyEnum.CTC_PATH_RECOMMEND_CACHE.getKey();
        List<CTCPathBaseVO> ctcPathBaseVOList = new ArrayList<>();
        List<CCPathEntity> pathEntities = pathDAO.findAllByRecommendAndDeletedOrderByRecommendDateDesc(8);
        if (CollectionUtils.isNotEmpty(pathEntities)) {
            ctcPathBaseVOList = pathEntities.stream().map(path -> {
                CTCPathBaseVO pathBase = new CTCPathBaseVO();
                pathBase.setId(path.getId());
                pathBase.setIcon(path.getIcon());
                pathBase.setName(path.getName());
                pathBase.setDescription(path.getDescription());
                pathBase.setSubMoney(path.getSubMoney());
                return pathBase;
            }).collect(Collectors.toList());
        }
        redisUtil.set(key, JsonUtil.toJsonString(ctcPathBaseVOList), RedisKeyEnum.CTC_PATH_RECOMMEND_CACHE.getExpireTime());
        return ctcPathBaseVOList;
    }

    private List<CTCPathBaseVO> refreshSubscribesPathCache() {
        String key = RedisKeyEnum.CTC_PATH_SUBSCRIBE_CACHE.getKey();
        List<CTCPathBaseVO> ctcPathBaseVOList = new ArrayList<>();
        List<CCPathEntity> pathEntities = pathDAO.findAllBySubscribePaths();
        if (CollectionUtils.isNotEmpty(pathEntities)) {
            ctcPathBaseVOList = pathEntities.stream().map(path -> {
                CTCPathBaseVO pathBase = new CTCPathBaseVO();
                pathBase.setId(path.getId());
                pathBase.setIcon(path.getIcon());
                pathBase.setLogo(path.getLogo());
                pathBase.setName(path.getName());
                pathBase.setDescription(path.getDescription());
                pathBase.setSubMoney(path.getSubMoney());
                return pathBase;
            }).collect(Collectors.toList());
        }
        redisUtil.set(key, JsonUtil.toJsonString(ctcPathBaseVOList), RedisKeyEnum.CTC_PATH_SUBSCRIBE_CACHE.getExpireTime());
        return ctcPathBaseVOList;
    }

    public List<CTCPathDetailVO> getUserAttendPathListFromCache(String userId, int size) {
        if (StringUtils.isBlank(userId)) {
            return Collections.emptyList();
        }
        AbstractResourceBehaviorService attendService =
                ResourceBehaviorFactory.getBehaviorService(ResourceBehaviorTypeEnum.FOCUS.getBehavior());
        List<Long> pathIdList = attendService.getUserBehaviorResourceIdListFromCache(userId,
                ResourceTypeEnum.CTC_PATH.getType(), ResourceBehaviorTypeEnum.FOCUS.getBehavior(), size);
        if (CollectionUtils.isEmpty(pathIdList)) {
            return Collections.emptyList();
        }
        Map<Long, CTCPathBaseVO> pathMap = batchGetPathBaseFromCache(pathIdList);
        Map<Long, Long> attendCountMap = attendService.getBehaviorCountFromCache(ResourceTypeEnum.CTC_PATH.getType(), pathIdList);
        List<CTCPathDetailVO> pathList = new ArrayList<>();
        for (Long pathId: pathIdList) {
            CTCPathBaseVO pathBaseVO = pathMap.get(pathId);
            CTCPathDetailVO pathDetailVO = new CTCPathDetailVO();
            pathDetailVO.setId(pathBaseVO.getId());
            pathDetailVO.setName(pathBaseVO.getName());
            pathDetailVO.setIcon(pathBaseVO.getIcon());
            pathDetailVO.setKw(pathBaseVO.getKw());
            pathDetailVO.setDescription(pathBaseVO.getDescription());
            pathDetailVO.setAttendCount(attendCountMap.getOrDefault(pathId, 0L));
            pathDetailVO.setIsAttend(true);
            pathList.add(pathDetailVO);
        }
        return pathList;
    }

    /**
     * 管理后台全部栏目管理查询
     * @param name
     * @param pageNo
     * @param pageSize
     * @return
     */
    public PAIPageResponseBeanUtil<List<CTCPathBaseVO>> pageList(String name, int pageNo, int pageSize) {
        Pageable pageable = PageRequest.of(pageNo - 1, pageSize, Sort.by(Sort.Order.desc("id")));
        Page<CCPathEntity> pathEntities;
        if (StringUtils.isBlank(name)) {
            pathEntities = pathDAO.findAll(pageable);
        } else {
            pathEntities = pathDAO.findAllByNameLike(name, pageable);
        }
        List<CTCPathBaseVO> pathBaseVOList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(pathEntities.getContent())) {
            pathBaseVOList = pathEntities.getContent().stream().map(p -> {
                CTCPathBaseVO pathBaseVO = new CTCPathBaseVO();
                BeanUtils.copyProperties(p, pathBaseVO);
                pathBaseVO.setCreateTime(p.getCreateDate().getTime());
                return pathBaseVO;
            }).collect(Collectors.toList());
        }
        return PAIPageResponseBeanUtil.success(pageNo, pageSize, pathEntities.getTotalElements(), pathBaseVOList);
    }

    public CTCPathDetailVO getCTCPathDetailVOFromCache(Long pathId) {
        return this.getPathBaseFromCache(pathId);
    }

    public CTCPathDetailVO getPathBaseFromCache(Long pathId) {
        String key = RedisKeyEnum.CTC_PATH_DETAIL_CACHE.getKey(pathId.toString());
        String cache = redisUtil.get(key);
        if (StringUtils.isNotBlank(cache)) {
            return JsonUtil.fromJson(cache, CTCPathDetailVO.class);
        }
        return this.refreshCTCPathDetailCacheByPathId(pathId);
    }

    public CTCPathDetailVO getPathBaseFromCache(Long pathId, String userId) {
        String key = RedisKeyEnum.CTC_PATH_DETAIL_CACHE.getKey(pathId.toString());
        String cache = redisUtil.get(key);
        CTCPathDetailVO path = new CTCPathDetailVO();
        if (StringUtils.isNotBlank(cache)) {
            path = JsonUtil.fromJson(cache, CTCPathDetailVO.class);
        } else {
            path = this.refreshCTCPathDetailCacheByPathId(pathId);
        }
        if (path != null) {
            path.setIsAttend(isAttendFromCache(userId, pathId));
        }
        return path;
    }

    private boolean isAttendFromCache(String userId, Long pathId) {
        if (StringUtils.isBlank(userId) || pathId == null) {
            return false;
        }
        AbstractResourceBehaviorService attendService =
                ResourceBehaviorFactory.getBehaviorService(ResourceBehaviorTypeEnum.FOCUS.getBehavior());
        List<Long> pathIdList = attendService.getUserBehaviorResourceIdListFromCache(userId,
                ResourceTypeEnum.CTC_PATH.getType(), ResourceBehaviorTypeEnum.FOCUS.getBehavior(), 1000);
        return pathIdList.contains(pathId);
    }

    public Map<Long, CTCPathBaseVO> batchGetPathBaseFromCache(List<Long> pathIdList) {
        List<String> keys = pathIdList.stream().map(id ->
                RedisKeyEnum.CTC_PATH_DETAIL_CACHE.getKey(id.toString())).collect(Collectors.toList());
        List<String> caches = redisUtil.mget(keys);
        Map<Long, CTCPathBaseVO> map = new HashMap<>();
        for (int i = 0; i < pathIdList.size(); i++) {
            Long pathId = pathIdList.get(i);
            String cache = caches.get(i);
            CTCPathBaseVO pathBase;
            if (StringUtils.isNotBlank(cache)) {
                pathBase = JsonUtil.fromJson(cache, CTCPathBaseVO.class);
            } else {
                pathBase = this.refreshCTCPathDetailCacheByPathId(pathId);
            }
            map.put(pathId, pathBase);
        }
        return map;
    }

    public List<CTCPathBaseVO> batchGetPathBaseListFromCache(List<Long> pathIdList) {
        List<String> keys = pathIdList.stream().map(id ->
                RedisKeyEnum.CTC_PATH_DETAIL_CACHE.getKey(id.toString())).collect(Collectors.toList());
        List<String> caches = redisUtil.mget(keys);
        List<CTCPathBaseVO> list = new ArrayList<>();
        for (int i = 0; i < pathIdList.size(); i++) {
            Long pathId = pathIdList.get(i);
            String cache = caches.get(i);
            CTCPathBaseVO pathBase;
            if (StringUtils.isNotBlank(cache)) {
                pathBase = JsonUtil.fromJson(cache, CTCPathBaseVO.class);
            } else {
                pathBase = this.refreshCTCPathDetailCacheByPathId(pathId);
            }
            list.add(pathBase);
        }
        return list;
    }

    public CTCPathDetailVO refreshCTCPathDetailCacheByPathId(Long pathId) {
        CCPathEntity path = pathDAO.findById(pathId).orElse(null);
        return this.refreshCTCPathDetailCacheByEntity(path);
    }

    private CTCPathDetailVO refreshCTCPathDetailCacheByEntity(CCPathEntity path) {
        if (path == null) {
            return null;
        }
        Long pathId = path.getId();
        CTCPathDetailVO vo = this.convertDetailVO(path);
        // 刷新关注人数
        AbstractResourceBehaviorService focusBehaviorService = ResourceBehaviorFactory.getBehaviorService(ResourceBehaviorTypeEnum.FOCUS.getBehavior());
        Long attendCount = focusBehaviorService.getBehaviorCountFromCache(ResourceTypeEnum.CTC_PATH.getType(), pathId);
        vo.setAttendCount(attendCount);
        // 刷新star数
        AbstractResourceBehaviorService starBehaviorService = ResourceBehaviorFactory.getBehaviorService(ResourceBehaviorTypeEnum.STAR.getBehavior());
        Long starCount = starBehaviorService.getBehaviorCountFromCache(ResourceTypeEnum.CTC_PATH.getType(), pathId);
        vo.setStarCount(starCount);
        vo.setQuestionCount(questionService.getQuestionCountFromCache(pathId));
        vo.setExperienceCount(experienceService.getExperienceCountFromCache(pathId));
        vo.setResourceCount(resourceService.getCTCResourceCountFromCache(pathId));
        vo.setVideoCount(resourceService.getCTCVideoCountFromCache(pathId));
        vo.setHotValue(culHotValue(vo.getAttendCount(), vo.getStarCount(),
                vo.getQuestionCount(), vo.getExperienceCount(), vo.getResourceCount(), vo.getVideoCount()));
        if (StringUtils.isNotBlank(path.getMenus())) {
            vo.setMenuCodes(ListUtil.string2List(path.getMenus()));
        }
        String key = RedisKeyEnum.CTC_PATH_DETAIL_CACHE.getKey(path.getId().toString());
        redisUtil.set(key, JsonUtil.toJsonString(vo), RedisKeyEnum.CTC_PATH_DETAIL_CACHE.getExpireTime());
        return vo;
    }

    /**
     * 计算社区热度
     *
     * @param attendCount
     * @param starCount
     * @param questionCount
     * @param experienceCount
     * @param resourceCount
     * @param videoCount
     * @return
     */
    private Long culHotValue(Long attendCount, Long starCount, Long questionCount, Long experienceCount, Long resourceCount, Long videoCount) {

        return attendCount * 5 + starCount * 2 + questionCount * 5 + resourceCount * 10 + experienceCount * 20 + experienceCount * 20;
    }

    public List<CTCPathDetailVO> getNewCTCPathListFromCache() {
        String key = RedisKeyEnum.CTC_PATH_NEW_ZSET_CACHE.getKey();
        if (!redisUtil.exists(key)) {
            refreshCTCNewPathCache();
        }
        Set<String> pathIdSet = redisUtil.zreverseRange(key, 0, 1000);
        if (CollectionUtils.isEmpty(pathIdSet)) {
            return Collections.emptyList();
        }
        List<Long> pathIdList = pathIdSet.stream().map(Long::valueOf).collect(Collectors.toList());
        Map<Long, CTCPathBaseVO> pathMap = batchGetPathBaseFromCache(pathIdList);
        AbstractResourceBehaviorService attendService =
                ResourceBehaviorFactory.getBehaviorService(ResourceBehaviorTypeEnum.FOCUS.getBehavior());
        Map<Long, Long> attendCountMap = attendService.getBehaviorCountFromCache(ResourceTypeEnum.CTC_PATH.getType(), pathIdList);
        List<CTCPathDetailVO> pathList = new ArrayList<>();
        for (Long pathId: pathIdList) {
            CTCPathBaseVO pathBaseVO = pathMap.get(pathId);
            CTCPathDetailVO pathDetailVO = new CTCPathDetailVO();
            pathDetailVO.setId(pathBaseVO.getId());
            pathDetailVO.setName(pathBaseVO.getName());
            pathDetailVO.setIcon(pathBaseVO.getIcon());
            pathDetailVO.setSubMoney(pathBaseVO.getSubMoney());
            pathDetailVO.setDescription(pathBaseVO.getDescription());
            pathDetailVO.setAttendCount(attendCountMap.getOrDefault(pathId, 0L));
            pathList.add(pathDetailVO);
        }
        return pathList;
    }

    public void refreshCTCNewPathCache() {
        List<CCPathEntity> pathEntities = pathDAO.findAllByStatus(CommonStatusEnum.PUBLISHED.getStatus());
        String key = RedisKeyEnum.CTC_PATH_NEW_ZSET_CACHE.getKey();
        redisUtil.remove(key);
        Set<ZSetOperations.TypedTuple<String>> tuples = pathEntities.stream().map(
                path -> {
                    String value = String.valueOf(path.getId());
                    Double score = Double.valueOf(path.getCreateDate().getTime());
                    return new DefaultTypedTuple<>(value, score);
                }).collect(Collectors.toSet());
        redisUtil.zadd(key, tuples, RedisKeyEnum.CTC_PATH_NEW_ZSET_CACHE.getExpireTime());
    }


    private boolean isExistKey(String key) {
        return redisUtil.exists(key);
    }

    private CCPathEntity save(CCPathEntity path) {
        return pathDAO.save(path);
    }


    private CCPathEntity convertEntity(CCPathSaveRequestVO pathSaveRequest, String userId) {
        Long id = pathSaveRequest.getId();
        CCPathEntity path;
        Date now = new Date();
        if (id != null) {
            path = pathDAO.findById(id).orElse(null);
            Assert.isTrue(path != null, "社区信息更新失败，栏目不存在!");
        } else {
            path = new CCPathEntity();
            path.setCreateBy(userId);
            path.setCreateDate(now);
            path.setStatus(CommonStatusEnum.NEW.getStatus());
        }
        path.setName(pathSaveRequest.getName());
        path.setDescription(pathSaveRequest.getDescription());
        path.setLogo(pathSaveRequest.getLogo());
        path.setIcon(pathSaveRequest.getIcon());
        path.setKw(pathSaveRequest.getKw());
        path.setMenus(pathSaveRequest.getMenus());
        return path;
    }

    private CTCPathDetailVO convertDetailVO(CCPathEntity path) {
        if (path == null) {
            return null;
        }
        CTCPathDetailVO vo = new CTCPathDetailVO();
        BeanUtils.copyProperties(path, vo);
        if (path.getCreateDate() != null) {
            vo.setCreateTime(path.getCreateDate().getTime());
        }
        return vo;
    }
}
